﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LineWatch_WinForm;

namespace DMSetup
{
    public partial class Form1 : Form
    {
        SerialPortOperator sp = new SerialPortOperator("COM1", 9600);
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string dmAddress = txtDM.Text.Trim();
            string dmData = txtData.Text.Trim();
            int outData;
            if (!int.TryParse(dmData, out outData))
            {
                MessageBox.Show("数据不是数字类型");
                return;
            }
            string command = "@00WD" + dmAddress.PadLeft(4, '0') + outData.ToString("X").PadLeft(4, '0');
            sp.WriteLine(command);
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            sp.ClosePort();
        }
    }
}
